<?php include $this->admin_tpl('meta');?>
<title>批量添加栏目 - YzmCMS内容管理系统</title>
<style>.exp{font-size:12px}.exp span{color:#959595;}</style>
</head>
<body>
<div class="page-container">
	<form class="form form-horizontal" method="" action="" onsubmit="return dosub(this)">
		<div id="tab_system" class="HuiTab">
			<div class="tabBar cl"><span>基本选项</span><span>模板设置</span></div>
			<div class="tabCon">
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>选择模型：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<span class="select-box">
						<select name="modelid" class="select" onchange="javascript:yzm_change_template(this.value)">
						  <?php 
						      foreach($modelinfo as $val){
									$str = $modelid==$val['modelid'] ? ' selected="selected" ' : '';
									echo '<option value="'.$val['modelid'].'"'.$str.'>'.$val['name'].'('.$val['alias'].')</option>';
							  }
							  if(!$modelinfo) echo '<option value="">暂无模型</option>';
						  ?>
						</select>
						</span>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>上级栏目：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<span class="select-box">
						 <?php echo select_category('parentid', $catid, '', 0, '', false, false); ?>
						</span>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>栏目名称：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<textarea class="textarea" name="catnames" placeholder="一行一个栏目，如：新闻中心|news" style="width:380px;float:left;margin-right:5px" onblur="yzmcms_pinyin()"></textarea>
						<div class="exp">例如：
							<br><span>新闻中心|news</span>
							<br>竖线以及后面的英文名可留空，
							<br>默认会自动生成栏目的拼音 
						</div>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2">栏目类型：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<label class="label_radio"><input name="type" type="radio" value="0" checked> 普通栏目</label>
						<!-- <label class="label_radio"><input name="type" type="radio" value="1"> 单页面</label> -->
					</div>
				</div>	
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2">打开方式：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<label class="label_radio"><input name="target" type="radio" value="_self" checked> 本窗口打开</label>
						<label class="label_radio"><input name="target" type="radio" value="_blank"> 新窗口打开</label>
					</div>
				</div>	
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2">导航显示：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<label class="label_radio"><input name="display" type="radio" value="1" checked> 是</label>
						<label class="label_radio"><input name="display" type="radio" value="0"> 否</label>
					</div>
				</div>		
			</div>
			<div class="tabCon">
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2">频道页模板：</label>
					<div class="formControls col-xs-8 col-sm-9 yzm-explain-box">
						<span class="select-box" style="width:400px">
						<select name="category_template" id="category_template" class="select">
						  <?php 
						      foreach($category_temp as $key => $val){
									$str = $parent_temp&&$key==$parent_temp['category_template'] ? ' selected="selected" ' : '';
									echo '<option value="'.$key.'"'.$str.'>'.$val.'('.$key.')</option>';
							  }
							  echo $category_temp ? '<option value="">不使用模板</option>' : '<option value="">暂无模板</option>';
						  ?>
						</select>
						</span>
						<span class="yzm-explain">频道页模板命名规则：<br>category_<i class="model_table"><?php echo $tablename;?></i>.html<br> 或 category_<i class="model_table"><?php echo $tablename;?></i>_*.html</span>
					</div>
				</div>	
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>列表页模板：</label>
					<div class="formControls col-xs-8 col-sm-9 yzm-explain-box">
						<span class="select-box" style="width:400px">
						<select name="list_template" id="list_template" class="select">
						  <?php 
						      foreach($list_temp as $key => $val){
									$str = $parent_temp&&$key==$parent_temp['list_template'] ? ' selected="selected" ' : '';
									echo '<option value="'.$key.'"'.$str.'>'.$val.'('.$key.')</option>';
							  }
							  if(!$list_temp) echo '<option value="">暂无模板</option>';
						  ?>
						</select>
						</span>
						<span class="yzm-explain">列表页模板命名规则：<br>list_<i class="model_table"><?php echo $tablename;?></i>.html<br> 或 list_<i class="model_table"><?php echo $tablename;?></i>_*.html</span>
					</div>
				</div>	
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>内容页模板：</label>
					<div class="formControls col-xs-8 col-sm-9 yzm-explain-box">
						<span class="select-box" style="width:400px">
						<select name="show_template" id="show_template" class="select">
						  <?php 
						      foreach($show_temp as $key => $val){
									$str = $parent_temp&&$key==$parent_temp['show_template'] ? ' selected="selected" ' : '';
									echo '<option value="'.$key.'"'.$str.'>'.$val.'('.$key.')</option>';
							  }
							  if(!$show_temp) echo '<option value="">暂无模板</option>';
						  ?>
						</select>
						</span>
						<span class="yzm-explain">内容页模板命名规则：<br>show_<i class="model_table"><?php echo $tablename;?></i>.html<br> 或 show_<i class="model_table"><?php echo $tablename;?></i>_*.html</span>
					</div>
				</div>					
			</div>
		</div>
		<div class="footer_btn_large">
			<input type="hidden" name="dosubmit" value="1">
			<input class="btn btn-primary radius" type="submit" value="提 交">
			<input class="btn btn-default radius" type="button" value="取 消" onclick="yzmcms_close()">	
		</div>
	</form>
</div>

<?php include $this->admin_tpl('footer');?>
<script type="text/javascript" src="<?php echo STATIC_URL;?>js/yzm-pinyin.js"></script> 

<script type="text/javascript">

var catdir_error = true;
function yzmcms_pinyin() {
	var reg = /^[a-zA-Z]{1}([a-zA-Z0-9]|[-/]){0,29}$/;
	var value = $(".textarea").val();
	var lines = value.split("\n");
	var str = '';
	for(var i=0; i<lines.length; i++){
		if(lines[i] == '') continue;
		if(lines[i].indexOf('|') < 0){
			lines[i] = lines[i].trim();
			var pinyin = codefans_net_CC2PY(lines[i]);
			lines[i] = lines[i]+'|'+pinyin.toLowerCase();
		}else{
			value = lines[i].split('|'); 
			if(!reg.test(value[1])){
				layer.msg('英文名称「'+value[1]+'」格式不正确！', {icon:2});
				return false;
			}
		}
		str = str+lines[i]+"\n";
	}
	catdir_error = false;
	$(".textarea").val(str);
}

function yzm_change_template(modelid){
	$.ajax({
		type: 'GET',
		url: '<?php echo U('public_category_template');?>?modelid='+modelid, 
		dataType: "json", 
		success: function (msg) {
			var category_template='',list_template='',show_template='';
			var options = '<option value="">暂无模板</option>';
			for(var info in msg.category_template) {
			    category_template += '<option value="'+info+'">'+msg.category_template[info]+'('+info+')</option>';
			}
			for(var info in msg.list_template) {
			    list_template += '<option value="'+info+'">'+msg.list_template[info]+'('+info+')</option>';
			}
			for(var info in msg.show_template) {
			    show_template += '<option value="'+info+'">'+msg.show_template[info]+'('+info+')</option>';
			}
			$('#category_template').html(category_template ? category_template+'<option value="">不使用模板</option>' : options);
			$('#list_template').html(list_template ? list_template : options);
			$('#show_template').html(show_template ? show_template : options);
			$('.model_table').html(msg.tablename);
		}
	})
}

function dosub(obj){
	if($("select[name='modelid']").val()==''){
		layer.msg('请新建模型后再创建栏目！', {icon:2});
		return false;
	}
	var reg = /^[a-zA-Z]{1}([a-zA-Z0-9]|[-/]){0,29}$/;
	if($("textarea[name='catnames']").val()==''){
		layer.msg('栏目名称不能为空！', {icon:2});
		return false;
	}
	if(catdir_error){
		layer.msg('栏目英文名称有错误，请检查！', {icon:2});
		return false;
	}
	// if($("select[name='category_template']").val()==''){
	// 	layer.msg('请选择频道页模板！', {icon:2});
	// 	$.Huitab("#tab_system .tabBar span","#tab_system .tabCon","current","click","1");
	// 	return false;
	// }
	if($("select[name='list_template']").val()==''){
		layer.msg('请选择列表页模板！', {icon:2});
		$.Huitab("#tab_system .tabBar span","#tab_system .tabCon","current","click","1");
		return false;
	}
	if($("select[name='show_template']").val()==''){
		layer.msg('请选择内容页模板！', {icon:2});
		return false;
	}		
	$.ajax({
		type: 'POST',
		url: '<?php echo U('adds');?>', 
		data: $(obj).serialize(),
		dataType: "json", 
		success: function (msg) {
			if(msg.status == 1){
				layer.msg(msg.message, {icon:1,time:1000}, function(){
					parent.location.reload();   
				});
			}else{
				layer.msg(msg.message, {icon:2});
			}
		}
	})
	return false;		
}

$(function(){
	$.Huitab("#tab_system .tabBar span","#tab_system .tabCon","current","click","<?php echo isset($_GET['tab']) ? intval($_GET['tab']) : '0'?>");
});
</script>

</body>
</html>